$zxt.PAGE = "CARD1";

var tmodel = new zxt.data.TunnelTableModel();
tmodel.method("query", "insert", "update", "remove");

function onInitialize(){		
	var accountIDTextBox = new zxt.ui.Textbox(true);
	$zxt.regComponent("accountID",accountIDTextBox);
	
	var nameTextBox = new zxt.ui.Textbox(true);
	$zxt.regComponent("name",nameTextBox);
	
	var genderChoose = new zxt.ui.Choose("Gendergroup");	
	var layoutCopy = $("#optionlayout").clone();
	genderChoose.setLayout(layoutCopy);
	layoutCopy.show();
	$zxt.regComponent("gender",genderChoose);
	
	var date = new zxt.ui.Datebox();
	$zxt.regComponent("birthday",date);
	
	var bankCombobox = new zxt.ui.Combobox(true,false);	
	bankCombobox.addOption("工商银行","工商银行");
	bankCombobox.addOption("招商银行","招商银行");
	bankCombobox.addOption("民生银行","民生银行");	
	$zxt.regComponent("bank",bankCombobox);
	
	var categorySelect = new zxt.ui.Select();
	$zxt.regComponent("category",categorySelect);
	
	var cardIDBox = new zxt.ui.Cardidbox("true");
	$zxt.regComponent("cardID",cardIDBox);
	
	
	
	var integraListbox = new zxt.ui.Listbox(false);
	integraListbox.addOption("太阳计划","Sun");
	integraListbox.addOption("水星计划","Mercury");
	integraListbox.addOption("金星计划","Venusun");
	integraListbox.addOption("地球计划","Earth");
	integraListbox.addOption("火星计划","Mars");
	
	$zxt.regComponent("integra",integraListbox);
};	




function configMainGrid(grid){
	grid.rowClicked = function(dom, idx){				
		var rowvalue = this._getRow(idx).getValue();
		$("#form").attr("value",idx);
		$("#accountID").text(rowvalue["accountID"]);
		$("#name").text(rowvalue["name"]);
		$("#gender").text(rowvalue["gender"]);
		$("#birthday").text(rowvalue["birthday"]);
		$("#bank").text(rowvalue["bank"]);
		$("#category").text(rowvalue["category"]);
		$("#cardID").text(rowvalue["cardID"]);
		$("#integra").text(rowvalue["integra"]);
				
		$zxtUI.EditBtn.setEnable(true);		
	}
};

function onClick$QueryBtn(){
	tmodel.setParam({id:"179371"});
}	

function onClick$AddBtn(){	
	 location.href = "CARD2.html";
}

function onClick$EditBtn(){	
	
	$zxtUI.accountID.setValue($("#accountID").text());	
	$("#accountID").text("");
	$("#accountID").append($zxtUI.accountID.render());
	
	$zxtUI.name._value = $("#name").text();
	$("#name").text("");
	$("#name").append($zxtUI.name.render());
	
	$zxtUI.gender._default = $("#gender").text();	
	$("#gender").text("");
	$("#gender").append($zxtUI.gender.render());
	
	$zxtUI.birthday._value = $("#birthday").text();
	$("#birthday").text("");
	$("#birthday").append($zxtUI.birthday.render());
	
	$zxtUI.bank._value = $("#bank").text();
	$("#bank").text("");
	$("#bank").append($zxtUI.bank.render());
	
	$zxtUI.category.addOption("个人普卡", "personalcard");
	$zxtUI.category.addOption("VIP卡", "vipcard");
	$zxtUI.category.addOption("公司卡", "companycard");
		
	$zxtUI.category._value = $("#category").text();
	$("#category").text("");
	$("#category").append($zxtUI.category.render());
	
	$zxtUI.cardID._value = $("#cardID").text();
	$("#cardID").text("");
	$("#cardID").append($zxtUI.cardID.render());
	
	$("#integra").text("");
	$("#integra").append($zxtUI.integra.render());
		
	$zxtUI.EditBtn.setEnable(false);		
	$zxtUI.SaveBtn.setEnable(true);		
}
 


function onClick$SaveBtn(){
	var callback = {
			onSuccess : function(ei) {
				alert(ei.message());
			},
			onFailure : function(xmlR, status, e) {
				alert("ERROR");
			}
		};
		
	var dw = new zxt.data.DataWrapper();
	dw.addComponent("accountID");
	dw.addComponent("name");
	dw.addComponent("gender");
	dw.addComponent("birthday");
	dw.addComponent("bank");
	dw.addComponent("category");
	dw.addComponent("cardID");
	dw.addComponent("integra");
	$zxt.commit(dw, callback);
	location.href = "CARD1.html"
}
